package main

import (
	"net/http"

	"github.com/gin-gonic/gin"

	"gitee.com/ProjectManageSys/auth"
	"gitee.com/ProjectManageSys/model"
	riskmanagement "gitee.com/ProjectManageSys/risk_management"
)

func main() {

	err_code := model.InitDB()
	if err_code != 0 {
		return
	}
	router := gin.Default()
	router.LoadHTMLGlob("html/*.html")
	router.Static("/assets", "./assets")
	router.GET("/", func(ctx *gin.Context) {
		ctx.JSON(http.StatusOK, gin.H{"message": "Hello, world!"})
	})
	// user management
	user := router.Group("/user")
	{
		// login
		user.GET("/login", func(ctx *gin.Context) {
			ctx.HTML(http.StatusOK, "login.html", gin.H{})
		})
		user.POST("/login", auth.Login)

		// user management
		user.GET("/manage", func(ctx *gin.Context) {
			ctx.HTML(http.StatusOK, "user_management.html", gin.H{})
		})
	}

	// risk management
	risk := router.Group("/risk")
	{
		risk.GET("/submit", riskmanagement.RiskSubmitPage)
		risk.POST("/submit", riskmanagement.RiskSubmit)
	}

	router.Run()
}
